package Servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import anonymus.excepcion.DAOExcepcion;
import anonymus.negocio.LocalNegocio;
import anonymus.modelo.Local;


/**
 * Servlet implementation class RegistrarLocalServlet
 */
@WebServlet("/RegistrarLocalServlet")
public class RegistrarLocalServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarLocalServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		LocalNegocio neg = new LocalNegocio();
		
		String nomlocal = request.getParameter("txtNombreLocal"); 
		String dirlocal = request.getParameter("txtDireccionLocal");
		String distlocal = request.getParameter("txtDistrito");
		String maplocal = request.getParameter("txtMapa");
		String tellocal = request.getParameter("txttelefonoLocal");
					
			 System.out.println("Grabado Satisfactoriamente");
             try {
                     neg.registrarLocal(nomlocal, dirlocal, distlocal,maplocal,tellocal,"jessica@gmail.com");
                     //response.sendRedirect(request.getContextPath() + "/Local.jsp");
                     RequestDispatcher rd=request.getRequestDispatcher("/Local.jsp");
         			 rd.forward(request, response);
         			 request.setAttribute("MENSAJE", "Se registro correctamente.");
             } catch (DAOExcepcion e) {
                     // TODO Auto-generated catch block
                  	 request.setAttribute("MENSAJE", e.getMessage());
                     
             }
	}

}
